
#include "ltdb.h"
#include "runlog.h"
#include "os/ltthread.h"
#include "utl.h"

runlog_info_t   runlog_info;

FILE*   log_file = NULL;

void
runlog_sys_init()
{
    log_file = fopen("run.log", "w+b");

    runlog_info.level = RUNLOG_DEBUG;
    runlog_info.print_type = RUNLOG_TYPE_SCR_AND_FILE;
}


void
runlog_print(
    schar*  _file,
    schar*  _func,
    uint32  _line,
    uint32  level,
    schar*  fmt,
    ...
)
{
    va_list     args;
    schar       msg[8192];

    if (level < runlog_info.level)
        return;

    va_start(args, fmt);
    vsprintf(msg, fmt, args);
    va_end(args);


}

void
runlog_error(
    schar*  _file,
    schar*  _func,
    uint32  _line,
    schar*  fmt,
    ...
)
{
    va_list     args;
    FILE*       err_file;
    schar       msg[8192] = {0};
    schar       time_str[64] = {0};
    schar*      p;

    err_file = fopen("lt_err.log", "a+b");

    lt_time_now_str(time_str);
    sprintf(msg, "[%s-0X%08X]@(%s,%s,%d) : ", time_str, thread_self_id(), _file, _func, _line);

    p = msg + strlen(msg);

    va_start(args, fmt);
    vsprintf(p, fmt, args);
    va_end(args);

    fprintf(err_file, "%s\n", msg);

    fclose(err_file);
}




void
runlog_sys_destroy()
{
    fclose(log_file);
}